package lc.二分;

/**
 * 搜索插入位置
 *
 * @author yang
 * @date 2021/12/25
 */
public class 搜索插入位置 {

    public int searchInsert(int[] nums, int target) {
        if (nums[nums.length - 1] < target) {
            return nums.length;
        }
        int l = 0, r = nums.length - 1;
        while (l < r) {
            int mid = l + r >> 1;
            if (nums[mid] >= target) r = mid;
            else l = mid + 1;
        }
        return l;
    }
}
